﻿using System;
using System.Collections.Generic;
using System.Text;
//using System.Linq;
using System.Data;

namespace PIM_ATE.Electrical
{
    class ClsDataCalResult
    {
        const string m_sRecordTableName = "[CalRecord]";
        const string m_sRecordItemTableName = "[CalRecordItem]";

        string m_sError;
        string m_sConnect;
        public bool isEnable = true;

        public ClsDataCalResult(string alias)
        {
            m_sConnect = alias;
            isEnable = IniFile.IniReadValue("Settings", "IsUploadData", "1") != "0";
        }

        public string error()
        {
            return m_sError;
        }

        public bool updateRecord(ClsCalRecord Record, List<ClsCalRecordItem> lstRecordItem)
        {
            if (!isEnable || GDefine.IS_UpLoadCalRecord) return false;
            string sCells = "";
            string sSqlRecord = "";
            string sSqlRecordItem = "";
            string IdIndex = "MOBI@IT";

            string sColNames_Record = PIMFunction.getColNameString(ClsCalRecord.getColNamesCalRecord());
            string sColNames_RecordItem = PIMFunction.getColNameString(ClsCalRecordItem.getColNamesCalRecordItem());

            string sRecordTime = PIMFunction.getTime(m_sConnect);
            if (sRecordTime == null || sRecordTime == "")
            {
                System.Windows.Forms.MessageBox.Show("无法获取服务器时间");
                return false;
            }
            //sRecordTime = "2018-06-07 21:01:50.513";
            DateTime dtRecordTime = DateTime.Parse(sRecordTime);
            Record.RecordTime = dtRecordTime;

            //var q = from a in lstRecordItem
            //        where a.Ispass == GDefine.ContentFail
            //        select new { a.Ispass }; 
            Record.IsPass = GDefine.ContentPass;

            for (int i = 0; i < lstRecordItem.Count; i++)
            {
                if (lstRecordItem[i].IsPass == GDefine.ContentFail) Record.IsPass = GDefine.ContentFail;
                #region PIMTestItem
                sCells = "";
                sCells += "'" + IdIndex + "',";
                sCells += "'" + Record.InstrumentID + "',";
                sCells += "'" + Record.RecordTime + "',";
                sCells += "'" + lstRecordItem[i].Port + "',";
                sCells += "'" + lstRecordItem[i].PortIndex + "',";
                sCells += "'" + lstRecordItem[i].Band + "',";
                sCells += "'" + lstRecordItem[i].ValueType + "',";
                sCells += "'" + lstRecordItem[i].Value + "',";
                sCells += "'" + lstRecordItem[i].Spec + "',";
                sCells += "'" + lstRecordItem[i].IsPass + "'";
                sSqlRecordItem += string.Format("insert into {0} ({1}) values ({2});\r\n",
                                                 m_sRecordItemTableName,
                                                 sColNames_RecordItem,
                                                 sCells);
                #endregion
            }
            #region PIMTest
            sCells = "";
            sCells += "'" + Record.InstrumentID + "',";
            sCells += "'" + Record.RecordTime + "',";
            sCells += "'" + Record.UserID + "',";
            sCells += "'" + Record.UserID2 + "',";
            sCells += "'" + Record.PCIP + "',";
            sCells += "'" + Record.ValueType + "',";
            sCells += "'" + Record.IsPass + "'";
            sSqlRecord = string.Format("insert into {0} ({1}) values ({2}) select @@identity as ID;\r\n",
                         m_sRecordTableName,
                         sColNames_Record,
                         sCells);
            #endregion

            try
            {
                using (var tran = MicroDBHelper.UseTransaction(IsolationLevel.RepeatableRead, m_sConnect))
                {
                    //执行更新
                    string ID = MicroDBHelper.ExecuteDataTable(sSqlRecord, null, m_sConnect).Rows[0]["ID"].ToString();
                    sSqlRecordItem = sSqlRecordItem.Replace(IdIndex, ID);
                    MicroDBHelper.ExecuteNonQuery(sSqlRecordItem, null, tran);
                    tran.MarkSuccess();

                    return true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return false;
        }

        public bool updateRecord(ClsCalRecord Record, List<ClsCalRecordItem> lstRecordItem, Dictionary<int, JcPIMDataMaxResult> m_dicResults)
        {
            if (!isEnable || GDefine.IS_UpLoadCalRecord) return false;
            string sCells = "";
            string sSqlRecord = "";
            string sSqlRecordItem = "";
            string IdIndex = "MOBI@IT";

            string sColNames_Record = PIMFunction.getColNameString(ClsCalRecord.getColNamesCalRecord());
            string sColNames_RecordItem = PIMFunction.getColNameString(ClsCalRecordItem.getColNamesCalRecordItem());

            string sRecordTime = PIMFunction.getTime(m_sConnect);
            if (sRecordTime == null || sRecordTime == "")
            {
                System.Windows.Forms.MessageBox.Show("无法获取服务器时间");
                return false;
            }
            //sRecordTime = "2018-06-07 21:01:50.513";
            DateTime dtRecordTime = DateTime.Parse(sRecordTime);
            Record.RecordTime = dtRecordTime;

            //var q = from a in lstRecordItem
            //        where a.Ispass == GDefine.ContentFail
            //        select new { a.Ispass }; 
            Record.IsPass = GDefine.ContentPass;

            for (int i = 0; i < lstRecordItem.Count; i++)
            {
                if (!m_dicResults.ContainsKey(i))
                    continue;
                lstRecordItem[i].Value = m_dicResults[i].fValue.ToString();
                lstRecordItem[i].IsPass = m_dicResults[i].sPass;

                if (lstRecordItem[i].IsPass == GDefine.ContentFail) Record.IsPass = GDefine.ContentFail;
                #region PIMTestItem
                sCells = "";
                sCells += "'" + IdIndex + "',";
                sCells += "'" + Record.InstrumentID + "',";
                sCells += "'" + Record.RecordTime + "',";
                sCells += "'" + lstRecordItem[i].Port + "',";
                sCells += "'" + lstRecordItem[i].PortIndex + "',";
                sCells += "'" + lstRecordItem[i].Band + "',";
                sCells += "'" + lstRecordItem[i].ValueType + "',";
                sCells += "'" + lstRecordItem[i].Value + "',";
                sCells += "'" + lstRecordItem[i].Spec + "',";
                sCells += "'" + lstRecordItem[i].IsPass + "'";
                sSqlRecordItem += string.Format("insert into {0} ({1}) values ({2});\r\n",
                                                 m_sRecordItemTableName,
                                                 sColNames_RecordItem,
                                                 sCells);
                #endregion
            }
            #region PIMTest
            sCells = "";
            sCells += "'" + Record.InstrumentID + "',";
            sCells += "'" + Record.RecordTime + "',";
            sCells += "'" + Record.UserID + "',";
            sCells += "'" + Record.UserID2 + "',";
            sCells += "'" + Record.PCIP + "',";
            sCells += "'" + Record.ValueType + "',";
            sCells += "'" + Record.IsPass + "'";
            sSqlRecord = string.Format("insert into {0} ({1}) values ({2}) select @@identity as ID;\r\n",
                         m_sRecordTableName,
                         sColNames_Record,
                         sCells);
            #endregion

            try
            {
                using (var tran = MicroDBHelper.UseTransaction(IsolationLevel.RepeatableRead, m_sConnect))
                {
                    //执行更新
                    string ID = MicroDBHelper.ExecuteDataTable(sSqlRecord, null, m_sConnect).Rows[0]["ID"].ToString();
                    sSqlRecordItem = sSqlRecordItem.Replace(IdIndex, ID);
                    MicroDBHelper.ExecuteNonQuery(sSqlRecordItem, null, tran);
                    tran.MarkSuccess();

                    return true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return false;
        }
        public bool isPassCal(string ip)
        {
            if (GDefine.IS_Cal_NOCHECEK) return true;

            string sRecordTime = PIMFunction.getTime(m_sConnect);
            if (sRecordTime == null || sRecordTime == "")
            {
                System.Windows.Forms.MessageBox.Show("无法获取服务器时间");
                return false;
            }
            DateTime dtRecordTime = DateTime.Parse(sRecordTime);

            string sSql = string.Format("select count(*) from {0} where PCIP='{1}' and IsPass='{2}' and {3} and [ValueType]='电性能'", m_sRecordTableName, ip, GDefine.ContentPass, getEleCalTimeBandSql(dtRecordTime));
            try
            {
                DataTable dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect);
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (int.Parse(dt.Rows[0][0].ToString()) > 0)
                        return true;
                    else
                        return false;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public bool isPassCal(string ip, string band)
        {
            if (GDefine.IS_Cal_NOCHECEK) return true;

            string sRecordTime = PIMFunction.getTime(m_sConnect);
            if (sRecordTime == null || sRecordTime == "")
            {
                System.Windows.Forms.MessageBox.Show("无法获取服务器时间");
                return false;
            }
            DateTime dtRecordTime = DateTime.Parse(sRecordTime);

            string sSql = string.Format("select count(*) from {0} c left join {1} i on c.InstrumentID=i.InstrumentID and c.ID=i.IdIndex  where c.PCIP='{2}' and c.IsPass='{3}'  and c.ValueType='交调'  and i.Band='{4}' and {5}", m_sRecordTableName, m_sRecordItemTableName, ip, GDefine.ContentPass, band, getPimCalTimeBandSql(dtRecordTime, "c"));
            try
            {
                DataTable dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect);
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (int.Parse(dt.Rows[0][0].ToString()) > 0)
                        return true;
                    else
                    {
                        m_sError = band + "频段仪表未校准！";
                        return false;
                    }                        
                }
                else
                {
                    m_sError = band + "频段仪表未校准！";
                    return false;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                return false;
            }
        }
        string getEleCalTimeBandSql(DateTime time)
        {
            var t1 = new TimeSpan(7, 50, 00);
            var t2 = new TimeSpan(20, 30, 00);
            var t3 = new TimeSpan(0, 0, 00);
            var t4 = new TimeSpan(23, 59, 59);
            string tt1 = time.ToShortDateString() + " " + t1,
                   tt2 = time.ToShortDateString() + " " + t2,
                   tt3 = time.ToShortDateString() + " " + t3,
                   tt4 = time.ToShortDateString() + " " + t4;
            if (time.TimeOfDay >= t1 && time.TimeOfDay < t2)
            {
                return string.Format("[RecordTime]>='{0}' and [RecordTime]<'{1}'", tt1, tt2);
            }
            else
            {
                return string.Format("(([RecordTime]>='{0}' and [RecordTime]<'{1}') or([RecordTime]>='{2}' and [RecordTime]<'{3}'))", tt3, tt1, tt2, tt4);
            }
        }

        string getPimCalTimeBandSql(DateTime time,string tbName)
        {
            var t1 = new TimeSpan(7, 50, 00);
            var t2 = new TimeSpan(12, 00, 00);
            var t3 = new TimeSpan(20, 30, 00);
            var t4 = new TimeSpan(23, 59, 59);
            var t5 = new TimeSpan(0, 0, 00);
            string tt1 = time.ToShortDateString() + " " + t1,
                   tt2 = time.ToShortDateString() + " " + t2,
                   tt3 = time.ToShortDateString() + " " + t3,
                   tt4 = time.ToShortDateString() + " " + t4,
                   tt5 = time.ToShortDateString() + " " + t5;
            if (time.TimeOfDay >= t1 && time.TimeOfDay < t2)
            {
                return string.Format("{0}.[RecordTime]>='{1}' and {0}.[RecordTime]<'{2}'", tbName,tt1, tt2);
            }
            else if (time.TimeOfDay >= t2 && time.TimeOfDay < t3)
            {
                return string.Format("{0}.[RecordTime]>='{1}' and {0}.[RecordTime]<'{2}'",tbName, tt2, tt3);
            }
            else if (time.TimeOfDay >= t3 && time.TimeOfDay < t4)
            {
                return string.Format("{0}.[RecordTime]>='{1}' and {0}.[RecordTime]<'{2}'",tbName, tt3, tt4);
            }
            else
            {
                return string.Format("{0}.[RecordTime]>='{1}' and {0}.[RecordTime]<'{2}'",tbName, tt5, tt1);
            }
        }
    }

    public class ClsCalInstrumentsInfo
    {
        public int ID { get; set; }
        public string InstrumentID { get; set; }
        public string InstrumentIP { get; set; }
        public string InstrumentBand { get; set; }
        public string InstrumentPortCount { get; set; }
        //0台式  1柜式
        public string InstrumentType { get; set; }
        public string InstrumentCalSpec { get; set; }
        public DateTime RecordTime { get; set; }
        public string UserID { get; set; }
        public string PCIP { get; set; }

        public static List<string> getColNamesInstrumentsInfo()
        {
            List<string> names = new List<string>();
            names.Add("InstrumentID");
            names.Add("InstrumentIP");
            names.Add("InstrumentBand");
            names.Add("InstrumentPortCount");
            names.Add("InstrumentType");
            names.Add("InstrumentCalSpec");
            names.Add("RecordTime");
            names.Add("UserID");
            names.Add("PCIP");
            return names;
        }

    }
    public class ClsCalInstrumentsInfoBuilder
    {
        const string m_sInstrumentsInfoTableName = "[CalInstrumentsInfo]";
        string m_sError;
        string m_sConnect;
        public bool isEnable = true;
        public ClsCalInstrumentsInfoBuilder(string alias)
        {
            m_sConnect = alias;
            isEnable = IniFile.IniReadValue("Settings", "IsUploadData", "1") != "0";
        }

        public string error()
        {
            return m_sError;
        }
        int iInstrumentID(string InstrumentID)
        {
            string sSql = string.Format("select count(*) from {0} where [InstrumentID]='{1}'", m_sInstrumentsInfoTableName, InstrumentID);
            try
            {
                DataTable dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect);
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (int.Parse(dt.Rows[0][0].ToString()) > 0)
                    {
                        m_sError = "该仪表信息已存在！";
                        return 1;
                    }
                    else
                        return 0;
                }
                else
                {
                    return 0;
                }
            }
            catch (Exception ex)
            {
                m_sError = ex.ToString();
                return -1;
            }
        }
        List<ClsCalInstrumentsInfo> dtToList(DataTable dt)
        {
            List<ClsCalInstrumentsInfo> LstInfo = new List<ClsCalInstrumentsInfo>();
            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ClsCalInstrumentsInfo info = new ClsCalInstrumentsInfo();
                    info.ID = Convert.ToInt32(dt.Rows[i]["ID"].ToString());
                    info.InstrumentBand = dt.Rows[i]["InstrumentBand"].ToString();
                    info.InstrumentCalSpec = dt.Rows[i]["InstrumentCalSpec"].ToString();
                    info.InstrumentID = dt.Rows[i]["InstrumentID"].ToString();
                    info.InstrumentIP = dt.Rows[i]["InstrumentIP"].ToString();
                    info.InstrumentPortCount = dt.Rows[i]["InstrumentPortCount"].ToString();
                    info.InstrumentType = dt.Rows[i]["InstrumentType"].ToString();
                    info.PCIP = dt.Rows[i]["PCIP"].ToString();
                    info.RecordTime = Convert.ToDateTime(dt.Rows[i]["RecordTime"].ToString());
                    info.UserID = dt.Rows[i]["UserID"].ToString();
                    LstInfo.Add(info);
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return LstInfo;
        }

        public bool insertData(ClsCalInstrumentsInfo info)
        {

            int iRes = iInstrumentID(info.InstrumentID);
            if (iRes != 0)
            {
                System.Windows.Forms.MessageBox.Show(error());
                return false;
            }

            string sColNames = PIMFunction.getColNameString(ClsCalInstrumentsInfo.getColNamesInstrumentsInfo());

            string sRecordTime = PIMFunction.getTime(m_sConnect);
            if (sRecordTime == null || sRecordTime == "")
            {
                System.Windows.Forms.MessageBox.Show("无法获取服务器时间");
                return false;
            }
            DateTime dtRecordTime = DateTime.Parse(sRecordTime);
            info.RecordTime = dtRecordTime;

            string sCells = "", sSql = "";
            #region PIMTest
            sCells = "";
            sCells += "'" + info.InstrumentID + "',";
            sCells += "'" + info.InstrumentIP + "',";
            sCells += "'" + info.InstrumentBand + "',";
            sCells += "'" + info.InstrumentPortCount + "',";
            sCells += "'" + info.InstrumentType + "',";
            sCells += "'" + info.InstrumentCalSpec + "',";
            sCells += "'" + info.RecordTime + "',";
            sCells += "'" + info.UserID + "',";
            sCells += "'" + info.PCIP + "'";
            sSql = string.Format("insert into {0} ({1}) values ({2}) \r\n",
                         m_sInstrumentsInfoTableName,
                         sColNames,
                         sCells);
            #endregion

            try
            {
                using (var tran = MicroDBHelper.UseTransaction(IsolationLevel.RepeatableRead, m_sConnect))
                {
                    MicroDBHelper.ExecuteNonQuery(sSql, null, tran);
                    tran.MarkSuccess();
                    return true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return false;
        }
        public bool deleteData(string ID)
        {
            string sSql = string.Format("delete from {0} where [ID]='{1}'", m_sInstrumentsInfoTableName, ID);
            try
            {

                if (MicroDBHelper.ExecuteNonQuery(sSql, null, m_sConnect) == -1)
                {
                    System.Windows.Forms.MessageBox.Show("删除失败！");
                    return false;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("删除成功！");
                    return true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return false;
            }
        }
        public bool updateData(ClsCalInstrumentsInfo info)
        {

            string sColNames = PIMFunction.getColNameString(ClsCalInstrumentsInfo.getColNamesInstrumentsInfo());

            string sRecordTime = PIMFunction.getTime(m_sConnect);
            if (sRecordTime == null || sRecordTime == "")
            {
                System.Windows.Forms.MessageBox.Show("无法获取服务器时间");
                return false;
            }
            DateTime dtRecordTime = DateTime.Parse(sRecordTime);
            info.RecordTime = dtRecordTime;

            string sSql = string.Format("update {0} set [InstrumentID] ='{1}',[InstrumentIP]='{2}',[InstrumentBand]='{3}',[InstrumentPortCount]='{4}',[InstrumentType]='{5}',[InstrumentCalSpec]='{6}',[RecordTime]='{7}',[UserID]='{8}',[PCIP]='{9}' where [ID]='{10}'\r\n",
                         m_sInstrumentsInfoTableName,
                         info.InstrumentID,
                         info.InstrumentIP,
                         info.InstrumentBand,
                         info.InstrumentPortCount,
                         info.InstrumentType,
                         info.InstrumentCalSpec,
                         info.RecordTime,
                         info.UserID,
                         info.PCIP,
                         info.ID);

            try
            {
                int i = MicroDBHelper.ExecuteNonQuery(sSql, null, m_sConnect, CommandType.Text);
                if (i >= 1)
                {
                    return true;
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return false;
        }
        public DataTable getDtInstrumentInfo()
        {
            string sSql = string.Format("select * from {0} order by [ID]", m_sInstrumentsInfoTableName);
            DataTable dt = new DataTable();
            try
            {
                dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect, CommandType.Text);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return dt;
        }
        public List<ClsCalInstrumentsInfo> getListInstrumentInfoByBandIp(string band, string ip, bool isUseIP = true)
        {
            string sSql = "";
            if (isUseIP)
            {
                sSql = string.Format("select * from {0} where [InstrumentBand]='{1}' and [InstrumentIP]='{2}'  order by [ID]", m_sInstrumentsInfoTableName,
                           band,
                           ip);
            }
            else
            {
                sSql = string.Format("select * from {0} where [InstrumentBand]='{1}' order by [ID]",
                           m_sInstrumentsInfoTableName,
                           band,
                           ip);
            }
            DataTable dt = new DataTable();
            try
            {
                dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect, CommandType.Text);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            List<ClsCalInstrumentsInfo> info = dtToList(dt);
            return info;
        }
        public string getSpecByInstrumentID(string IDN)
        {
            string sSql = string.Format("select top 1 [InstrumentCalSpec] from {0} where [InstrumentID]='{1}'", m_sInstrumentsInfoTableName, IDN);
            string spec = "";
            try
            {
                DataTable dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect, CommandType.Text);
                spec = dt.Rows[0][0].ToString();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            return spec;
        }
        public List<string> getInstrumentIDByBandIp(string band, string ip, bool isUseIP = true)
        {
            string sSql = "";
            if (isUseIP)
            {
                sSql = string.Format("select [InstrumentID] from {0} where [InstrumentBand]='{1}' and [InstrumentIP]='{2}'  order by [ID]", m_sInstrumentsInfoTableName,
                           band,
                           ip);
            }
            else
            {
                sSql = string.Format("select [InstrumentID] from {0} where [InstrumentBand]='{1}' order by [ID]",
                           m_sInstrumentsInfoTableName,
                           band,
                           ip);
            }
            DataTable dt = new DataTable();
            try
            {
                dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect, CommandType.Text);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            if (dt == null || dt.Rows.Count < 1) return null;
            List<string> lstIDN = new List<string>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lstIDN.Add(dt.Rows[i][0].ToString());
            }
            return lstIDN;
        }
        public ClsCalInstrumentsInfo getInstrumentInfoByInstrumentID(string IDN)
        {
            string sSql = string.Format("select top 1 * from {0} where [InstrumentID]='{1}' ", m_sInstrumentsInfoTableName,
                           IDN);
            DataTable dt = new DataTable();
            try
            {
                dt = MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect, CommandType.Text);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            List<ClsCalInstrumentsInfo> info = dtToList(dt);
            return info[0];
        }
    }

    public class ClsCalRecord
    {
        public int ID { get; set; }
        public string InstrumentID { get; set; }
        public DateTime RecordTime { get; set; }
        public string UserID { get; set; }
        public string UserID2 { get; set; }
        public string PCIP { get; set; }
        public string ValueType { get; set; }
        public string IsPass { get; set; }

        public static List<string> getColNamesCalRecord()
        {
            List<string> names = new List<string>();
            names.Add("InstrumentID");
            names.Add("RecordTime");
            names.Add("UserID");
            names.Add("UserID2");
            names.Add("PCIP");
            names.Add("ValueType");
            names.Add("IsPass");
            return names;
        }
    }
    public class ClsCalRecordItem
    {
        public int ID { get; set; }
        public int IdIndex { get; set; }
        public string InstrumentID { get; set; }
        public DateTime RecordTime { get; set; }
        //1-2,1-3..
        public string Port { get; set; }
        //1,2,3,4..S11 S22 S21
        public string PortIndex { get; set; }
        public string Band { get; set; }
        public string ValueType { get; set; }
        public string Value { get; set; }
        public string Spec { get; set; }
        public string IsPass { get; set; }

        public static List<string> getColNamesCalRecordItem()
        {
            List<string> names = new List<string>();
            names.Add("IdIndex");
            names.Add("InstrumentID");
            names.Add("RecordTime");
            names.Add("Port");
            names.Add("PortIndex");
            names.Add("Band");
            names.Add("ValueType");
            names.Add("Value");
            names.Add("Spec");
            names.Add("IsPass");
            return names;
        }
    }
}
